package com.ithema.dao;

import com.itheima.dao.BaseStudentDao;
import com.itheima.domain.Student;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class StudentDao_JDBC implements BaseStudentDao{

    private static final Logger LOGGER = LoggerFactory.getLogger(StudentDao_JDBC.class);
    @Override
    public boolean addStudent(Student stu) {
        Connection conn = null;
        PreparedStatement psmt = null;
        try {
            conn = getConnection();

            //定义sql
            String sql = "INSERT INTO student() VALUES (?,?,?,?)";

            //获取sql执行对象
            psmt = conn.prepareStatement(sql);
            psmt.setString(1, stu.getId());
            psmt.setString(2, stu.getName());
            psmt.setString(3, stu.getAge());
            psmt.setString(4, stu.getBirthday());

            //执行sql
            long affNum = psmt.executeLargeUpdate();

            if (affNum > 0){
                return true;
            }else {
                return false;
            }
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
        }finally {
            close(conn, psmt, null);
        }
        return false;
        return false;
    }

    @Override
    public List<Student> findAllStudent() {
        return null;
    }

    @Override
    public boolean deleteStudent(String delId) {
        return false;
    }

    @Override
    public boolean updateStudent(String updateId, Student newStu) {
        return false;
    }

    @Override
    public int getIndex(String id) {
        return 0;
    }
}
